package com.yupi.springbootinit.statemachine.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yupi.springbootinit.statemachine.core.StateTransitionRecord;
import com.yupi.springbootinit.statemachine.dto.StateTransitionRecordQueryRequest;
import com.yupi.springbootinit.statemachine.vo.StateTransitionStatisticsVO;

import java.util.List;
import java.util.Map;

/**
 * 状态转换记录服务接口
 */
public interface StateTransitionRecordService extends IService<StateTransitionRecord> {
    
    /**
     * 分页查询状态转换记录
     */
    IPage<StateTransitionRecord> queryRecords(StateTransitionRecordQueryRequest request);
    
    /**
     * 查询指定实体的状态转换历史
     */
    List<StateTransitionRecord> getEntityTransitionHistory(String entityType, Long entityId);
    
    /**
     * 查询用户有权限查看的状态转换记录
     */
    IPage<StateTransitionRecord> queryRecordsWithPermission(StateTransitionRecordQueryRequest request, Long userId);
    
    /**
     * 获取状态转换统计信息
     */
    StateTransitionStatisticsVO getTransitionStatistics(String entityType, String startTime, String endTime);
    
    /**
     * 获取转换频次统计
     */
    List<Map<String, Object>> getTransitionFrequencyStats(String entityType, String startTime, String endTime);
    
    /**
     * 获取转换耗时分析
     */
    List<Map<String, Object>> getTransitionDurationAnalysis(String entityType, String startTime, String endTime);
    
    /**
     * 获取异常转换统计
     */
    List<StateTransitionRecord> getFailedTransitions(String entityType, String startTime, String endTime, Integer limit);
    
    /**
     * 获取操作人转换统计
     */
    List<Map<String, Object>> getOperatorTransitionStats(String startTime, String endTime);
    
    /**
     * 获取慢转换记录
     */
    List<StateTransitionRecord> getSlowTransitions(Long thresholdMs, Integer limit);
    
    /**
     * 导出状态转换记录
     */
    List<StateTransitionRecord> exportRecords(StateTransitionRecordQueryRequest request, Long userId);
    
    /**
     * 获取实体状态转换链路
     */
    List<StateTransitionRecord> getEntityTransitionChain(String entityType, Long entityId);
    
    /**
     * 验证用户是否有权限查看指定记录
     */
    boolean hasPermissionToViewRecord(Long userId, StateTransitionRecord record);
}